package com.ruoyi.transaction.controller;


import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.entity.TransactionEntity.VO.SpuWithPrice;
import com.ruoyi.transaction.service.ISpuWithPriceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * SPU带价格Controller
 *
 * @author ruoyi
 */
@Slf4j
@RestController
@RequestMapping("/SpuWithPrice")
public class SpuWithPriceController extends BaseController {

    @Autowired
    private ISpuWithPriceService spuWithPriceService;

    /**
     * 根据ID范围查询SPU带价格信息
     *
     * @param startId 起始ID
     * @param endId 结束ID
     * @return SPU带价格列表
     */
    @GetMapping("/range")
    public AjaxResult getSpuWithPriceByRange(
            @RequestParam Long startId,
            @RequestParam Long endId) {
        try {
            // 参数验证
            if (startId == null || endId == null) {
                return AjaxResult.error("起始ID和结束ID不能为空");
            }

            if (startId > endId) {
                return AjaxResult.error("起始ID不能大于结束ID");
            }

            if (endId - startId > 1000) {
                return AjaxResult.error("查询范围过大，最多支持1000条记录");
            }

            List<SpuWithPrice> result = spuWithPriceService.selectSpuWithPriceByRange(startId, endId);

            return AjaxResult.success("查询成功", result);
        } catch (Exception e) {
            log.error("根据ID范围查询SPU失败", e);
            return AjaxResult.error("查询失败: " + e.getMessage());
        }
    }

    /**
     * 根据ID列表查询SPU带价格信息
     *
     * @param ids ID列表
     * @return SPU带价格列表
     */
//    @PostMapping("/list")
//    public AjaxResult getSpuWithPriceByIds(@RequestBody List<Long> ids) {
//        try {
//            // 参数验证
//            if (ids == null || ids.isEmpty()) {
//                return AjaxResult.error("ID列表不能为空");
//            }
//
//            if (ids.size() > 100) {
//                return AjaxResult.error("ID列表过大，最多支持100个ID");
//            }
//
//            List<SpuWithPrice> result = spuWithPriceService.selectSpuWithPriceByIds(ids);
//
//            return AjaxResult.success("查询成功", result);
//        } catch (Exception e) {
//            log.error("根据ID列表查询SPU失败", e);
//            return AjaxResult.error("查询失败: " + e.getMessage());
//        }
//    }
}